package com.wx.service.impl;

import com.wx.domain.dto.AgreementDto;
import com.wx.domain.vo.NurseAgreementVo;
import com.wx.domain.vo.PatientAgreementVo;
import com.wx.entity.SysAgreement;
import com.wx.mapper.SysAgreementMapper;
import com.wx.properties.OssProperties;
import com.wx.service.SysAgreementService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;


/**
 * <p>Title:      SysAgreementServiceImpl. </p>
 * <p>Description 协议签署表 </p>
 * <p>Copyright: Copyright (c) 2016</p>
 * <p>Company:    医百科技有限公司 </p>
 *
 * @author         yangwensheng@100doc.com.cn
 * @since      2021-03-25 10:08:31
 */
@Service
public class SysAgreementServiceImpl extends BaseServiceImpl<SysAgreement> implements SysAgreementService {

    @Resource
    private SysAgreementMapper sysAgreementMapper;

    @Resource
    private OssProperties ossProperties;


    @Override
    public int updateByUserId(SysAgreement deleteAgreement) {
        return sysAgreementMapper.updateByUserId(deleteAgreement);
    }

    @Override
    public List<PatientAgreementVo> listPageWithPatient(AgreementDto param) {
        List<PatientAgreementVo> patientAgreementVos = sysAgreementMapper.listPageWithPatient(param);
        if(!CollectionUtils.isEmpty(patientAgreementVos)){
            for (PatientAgreementVo patientAgreementVo : patientAgreementVos) {
                patientAgreementVo.setFileUrl(ossProperties.getUrl() + patientAgreementVo.getFileUrl());
            }

        }
        return patientAgreementVos;
    }

    @Override
    public List<SysAgreement> batchQueryByPatientIds(List<String> patientIds, Integer userType) {
        return sysAgreementMapper.batchQueryByPatientIds(patientIds,userType);
    }

    @Override
    public List<NurseAgreementVo> listPageWithNurse(AgreementDto param) {
        List<NurseAgreementVo> nurseAgreementVos = sysAgreementMapper.listPageWithNurse(param);
        if(!CollectionUtils.isEmpty(nurseAgreementVos)){
            for (NurseAgreementVo nurseAgreementVo : nurseAgreementVos) {
                nurseAgreementVo.setFileUrl(ossProperties.getUrl() + nurseAgreementVo.getFileUrl());
            }
        }
        return nurseAgreementVos;
    }
}
